<extend name="Include:Layout"/>
<block name="title">自定义报名</block>
<block name="style">
<style>
#lesson_popup header h1{
    font-size: 18px;
    line-height:40px;
    color: #3cc51f;
    font-weight: 400;
    float:left;
    padding-left:15px;
  }
#lesson_popup td{border:solid #ddd; border-width:0px 1px 1px 0px;text-align:center;font-size:14px;line-height:30px;}
#lesson_popup table{border:solid #ddd; border-width:1px 0px 0px 1px;}
#lesson_popup td b{font-size:16px;padding-left:15px;}
  .choice {background-color:#EFEFF4;color:#04BE02;}
 .text-info {color:#999;text-align:center;padding-top:10px;padding-bottom:10px;}
 .enable {color:#999;}
.weui_cells {font-size:14px;}
  .cell_xiaoqu_desc {color:#888; font-size:12px;}
  #tabledata td {font-size:12px;}
  
.toolbar .left-button {
    position: absolute;
    left: 0;
    box-sizing: border-box;
    height: 2.2rem;
    line-height: 2.2rem;
    color: #04BE02;
    z-index: 1;
    padding: 0 .5rem;
}
</style>
</block>

<block name="main">
<div class="weui_tab">
  <div class="weui_navbar">
  	  <!-- <div class="weui_navbar_item " onclick="self.location='{:U('baoming/index')}'">课程报名</div> -->
  	  <div class="weui_navbar_item weui_bar_item_on" >自定义报名</div>
  </div>
  <div class="weui_tab_bd">
    <div class="weui_tab_bd_item weui_tab_bd_item_active">
    	<div class="weui_cells_title" style="font-size:12px;">
    	  	{$title}
    	 </div>
    	<div class="weui_cells weui_cells_form">
		  <div class="weui_cell">
		    <div class="weui_cell_hd"><label class="weui_label">学生姓名</label></div>
		    <div class="weui_cell_bd weui_cell_primary">
		      <input class="weui_input" type="text" name="studentname" value="{$old.student}" <if condition="$old">readonly</if> placeholder="请输入学生姓名"/>
		    </div>
		  </div>
		  <div class="weui_cell">
		    <div class="weui_cell_hd"><label class="weui_label">出生年月</label></div>
		    <div class="weui_cell_bd weui_cell_primary">
		      <input class="weui_input" type="text" name="birthday" id="birthday" value="" readonly data-toggle='date'/>
		    </div>
		  </div>
		  <div class="weui_cell">
		    <div class="weui_cell_hd"><label class="weui_label">手机号码</label></div>
		    <div class="weui_cell_bd weui_cell_primary">
		    	<php>$mobile = $_SESSION['_loginUser_home']['mobile'];</php>
		      <input class="weui_input" type="tel" name="mobile" value="{$old.tel|default=$mobile}" <if condition="$old">readonly</if> placeholder="请输入手机号码"/>
		    </div>
		  </div>
		  <div class="weui_cell">
		    <div class="weui_cell_hd"><label for="" class="weui_label">家长姓名</label></div>
		    <div class="weui_cell_bd weui_cell_primary">
		    	<php>$jzxm = $_SESSION['_loginUser_home']['realname'];</php>
		      <input class="weui_input" type="text" name="jzxm" value="{$old.jzxm|default=$jzxm}" <if condition="$old">readonly</if>/>
		    </div>
		  </div>
		  <div class="weui_cell app_select">
		    <div class="weui_cell_hd"><label class="weui_label">校区</label></div>
		    <div class="weui_cell_bd weui_cell_primary">
		    	<input class="weui_input" id="xiaoqu" type="text" name="xiaoqu" value=""  placeholder="点击选择校区" readonly data-values="0">
		    </div>
		    <span class="weui_cell_ft"></span>
		  </div>
		  <div class="weui_cell app_select banjiDom" style="display:none;">
		    <div class="weui_cell_hd"><label class="weui_label">课程</label></div>
		    <div class="weui_cell_bd weui_cell_primary">
		    	<input class="weui_input" id="banji" type="text" name="banji" readonly value="" data-values="0">
		    </div>
		    <span class="weui_cell_ft"></span>
		  </div>
		  
		  <div class="weui_cell app_select banjiDom" style="display:none;">
		   	<div class="weui_cell_hd"><label class="weui_label">班级</label></div>
		    <div class="weui_cell_bd weui_cell_primary">
		    	<input class="weui_input" id="lesson"  type="text" name="lesson" readonly value="" data-lid="">
		    </div>
		  	<span class="weui_cell_ft"></span>
		  </div>
		  <div class="weui_cell app_select banjiDom" style="display:none;">
		    <div class="weui_cell_hd"><label class="weui_label">学期</label></div>
		    <div class="weui_cell_bd weui_cell_primary">
		    	<input class="weui_input" id="xueqi" type="text" readonly name="xueqi" value="" data-id="0" data-title="">
		    </div>
		    <span class="weui_cell_ft"></span>
		  </div>
		  <div class="weui_cell">
		    <div class="weui_cell_hd"><label class="weui_label">金额</label></div>
		    <div class="weui_cell_bd weui_cell_primary">
		    	<input class="weui_input" type="number" name="total" id="total"  value="">
		    </div>
		  </div>
		  <div class="weui_cells_title" style="font-size:12px;color:red">金额请跟前台服务人员确认，否则报名无效</div>
		  <div class="weui_cells_title">备注</div>
			<div class="weui_cells weui_cells_form">
			  <div class="weui_cell">
			    <div class="weui_cell_bd weui_cell_primary">
			      <textarea class="weui_textarea" id="beizhu" placeholder="" rows="3"></textarea>
			    </div>
			  </div>
			</div>
		</div>
		
		<div style="padding:15px;">
			<input type="hidden" name="studentstatus" value="{$t}"/>
			<input type="hidden" name="uid" value="{$_SESSION['_loginUser_home']['uid']}"/>
			<button class="weui_btn weui_btn_primary btncheckorder">提交</button>
		</div>
    </div>
  </div>
</div>


<div id="xiaoqu_popup" class="weui-popup-container">
  <div class="weui-popup-modal" style="background:#fff;">
    <div class="toolbar">
          <div class="toolbar-inner">
            <a href="javascript:;" class="picker-button closebtn">关闭</a>
            <h1 class="title" id="xiaoqu_title">选择校区</h1>
          </div>
    </div>
    <div class="modal-content">
	    <div class="weui_panel weui_panel_access" style="margin-top:0;">
	      <div class="weui_panel_bd"> 
	        <div class="weui_cells weui_cells_radio" id="xiaoqu_data">
			 
			</div>
	      </div>
	    </div>
    </div>
  </div>
</div>
<script id="xiaoqu_data_html" type="text/html">
{{each list as value index}}
<div class="weui_cell weui_check_label xiaoqu_class" onclick="get_xiaoqu('{{value.title}}',{{value.id}})" for="xq{{index}}" data-title="{{value.title}}" data-id="{{value.id}}">
	<div class="weui_cell_bd weui_cell_primary">
		<p><span class="cell_xiaoqu">{{value.title}}</span> <br/><span class="cell_xiaoqu_desc">电话：{{value.tel}}</span><br/><span class="cell_xiaoqu_desc">地址：{{value.address}}</span></p>
	</div>
	<div class="weui_cell_ft">
		{{if did == value.id}}
		<input type="radio" class="weui_check" name="radio_xq" checked="checked"  id="xq{{index}}" >
		{{else}}
		<input type="radio" class="weui_check" name="radio_xq"  id="xq{{index}}" >
		{{/if}}
		<span class="weui_icon_checked"></span>
	</div>
</div>
{{/each}}
</script>

<div id="kecheng_popup" class="weui-popup-container">
  <div class="weui-popup-modal" id="kecheng_data" style="background:#fff;">
    
  </div>
</div>

<script id="banji_data_html" type="text/html">
<div class="toolbar">
	<div class="toolbar-inner">
    	<a href="javascript:;" class="picker-button goxiaoqu">校区</a>
        <h1 class="title" id="banji_title">{{title}}</h1>
    </div>
</div>
    <div class="modal-content">
	    <div class="weui_panel weui_panel_access" style="margin-top:0;">
	      <div class="weui_panel_bd"> 
	        <div class="weui_cells weui_cells_radio" >
			 	{{each list as value index}}
				<div class="weui_cell weui_check_label kecheng_class" for="kc{{index}}" onclick="get_kecheng('{{value.title}}',{{value.id}})"  data-title="{{value.title}}" data-id="{{value.id}}">
 					<div class="weui_cell_bd weui_cell_primary">
						<span class="cell_xiaoqu">{{value.title}}</span> <br/><span class="cell_xiaoqu_desc">{{value.desc}}</span>
					</div>
					<div class="weui_cell_ft">
					{{if cid == value.id}}
					<input type="radio" class="weui_check" name="radio_kc" checked="checked"  id="kc{{index}}" >
					{{else}}
					<input type="radio" class="weui_check" name="radio_kc" id="kc{{index}}">
					{{/if}}
	    			<span class="weui_icon_checked"></span>
				</div>
			</div>
			{{/each}}
			</div>
	      </div>
	    </div>
    </div>

</script>

<div id="lesson_popup" class="weui-popup-container">
  <div class="weui-popup-modal" id="lesson_data" style="background:#fff;">

  </div>
</div>

<script id="lesson_data_html" type="text/html">
    <div class="toolbar">
          <div class="toolbar-inner">
            <a href="javascript:;" class="picker-button gokecheng">课程</a>
            <h1 class="title" id="lesson_title">{{title}}</h1>
          </div>
    </div>
    <div class="modal-content">
	    <div class="weui_panel weui_panel_access" style="margin-top:0;">
	      <div class="weui_panel_bd" style="padding:20px;"> 
	        <table id="tabledata" style="width:100%;" cellpadding="0" cellspacing="0">
	       		<tr>
			      	<td>班级</td>
					<td>对象</td>
					<td>类型</td>
					<td>时间</td>
				</tr>
				{{each list as value index}}
				<tr class="lesson_class {{if lid == value.id}}choice{{/if}}" onclick="get_lesson('{{value.lessoncode}}',{{value.id}})"  data-value="{{value.lessoncode}}" data-lid="{{value.id}}">
					<td>{{value.lessoncode}}</td>
					<td>{{value.tar}}</td>
					<td>{{value.lessontype}}</td>
					<td>{{value.lessontime}}</td>
				</tr>
				{{/each}}
	        </table>
	      </div>
	    </div>
    </div>
	
</script>



<div id="xueqi_popup" class="weui-popup-container popup-bottom">
  <div class="weui-popup-overlay"></div>
  <div class="weui-popup-modal" id="xueqi_data" style="background:#fff;">
    
  </div>
</div>

<script id="xueqi_data_html" type="text/html">
<div class="toolbar">
	<div class="toolbar-inner">
		<a href="javascript:;" class="picker-button gobanji">班级</a>
		<h1 class="title" id="xueqi_title">{{title}}</h1>
	</div>
</div>
<div class="modal-content">
	<div class="weui_panel weui_panel_access" style="margin-top:0;">
		<div class="weui_panel_bd"> 
	        <div class="weui_cells weui_cells_radio" >
				{{each list as value index}}
			 	<div class="weui_cell weui_check_label xueqi_class" onclick="get_xueqi({{value.tid}},'{{value.minititle}}',{{value.value}})" data-tid="{{value.tid}}" data-title="{{value.minititle}}" data-value="{{value.value}}" for="xueqi{{index}}">
				<div class="weui_cell_bd weui_cell_primary">
					<div class="cell_xiaoqu_desc">
						<b style="padding-right:10px;color:#333">{{value.term_title}}</b>
						<b style="color:#333">|</b>
						<span style="margin-left:10px">{{value.termhtml | decodehtmljson}}{{value.title | decodehtmljson}}</span><br/>
						<!--<span class="cell_xiaoqu">费用：{{value.value}}元</span>-->
					</div>
				</div>
				<div class="weui_cell_ft">
					{{if tid == value.tid}}
					<input type="radio" class="weui_check" name="radio_xueq" checked="checked"  id="xueqi{{index}}" >
					{{else}}
					<input type="radio" class="weui_check" name="radio_xueq" id="xueqi{{index}}">
					{{/if}}
					<span class="weui_icon_checked"></span>
				</div>
				</div>
				{{/each}}
			</div>
		</div>
	</div>
</div>
</script>

</block>

<block name="script">
<script>
$(".closebtn").click(function(){
	$("#total").val('');
	$('.banjiDom').hide();
	$.closePopup();
	
})

$("#birthday").calendar();

$(document).on('click','.goxiaoqu',function(){
	$.closePopup();
	$("#xiaoqu").trigger('click');
})

$(document).on('click','.gokecheng',function(){
	$.closePopup();
	$("#banji").trigger('click');
})

$(document).on('click','.gobanji',function(){
	$.closePopup();
	$("#lesson").trigger('click');
})

$("#xiaoqu").click(function(){
	$.showLoading();
	var did = $(this).attr("data-values");
	if(!did) did = 0;
	$.get('/api/ygcl/getxiaoqu_new',function(ret){
		if(ret.status){
			var data = {
				'did':did,
				'list':ret.data
			}
			var html = template("xiaoqu_data_html", data);
			$("#xiaoqu_data").html(html);
			$.hideLoading();
			$("#xiaoqu_popup").popup();
		}else{
			$.alert('无校区','');
		}
	})
})
function get_xiaoqu(title,id){
	$("#xiaoqu").val(title);
	$("#xiaoqu").attr("data-values",id);
	
	$("#banji").val('');
	$("#banji").attr("data-values",'0');
	$("#lesson").val('');
	$("#lesson").attr("data-values",'0');
	$("#xueqi").val('');
	$("#xueqi").attr("data-values",'0');
	$("#total").val('');
	
	$.closePopup();
	$("#banji").trigger('click');
}


$("#banji").click(function(){
	$.showLoading();
	var cid = $(this).attr("data-values");
	var did = $("#xiaoqu").attr("data-values");
	var title = $("#xiaoqu").val();
	if(!cid) cid = 0;
	$.get('/api/ygcl/getclass_new_for_midpay',{did:did},function(ret){
		if(ret.status){
			var data = {
				'cid':cid,
				'title':title,
				'list':ret.data
			}
			var html = template("banji_data_html", data);
			$("#kecheng_data").html(html);
			$.hideLoading();
			$("#kecheng_popup").popup();
		}else{
			$.alert('无课程信息','')
		}
	})
})

function get_kecheng(title,id){
	$("#banji").val(title);
	$("#banji").attr("data-values",id);
	
	$("#lesson").val('');
	$("#lesson").attr("data-values",'0');
	$("#xueqi").val('');
	$("#xueqi").attr("data-values",'0');
	$("#total").val('');
	
	$.closePopup();
	$("#lesson").trigger('click');
}

$("#lesson").click(function(){
	var cid = $('#banji').attr('data-values');
	var title = $("#banji").val();
	var lid = $(this).attr('data-values');
	if(!lid) lid=0;
	$.get('/api/ygcl/getlesson_new',{cid:cid},function(ret){
		if(ret.status){
			var data = {
				'lid':lid,
				'title':title,
				'list':ret.data
			}
			var html = template("lesson_data_html", data);
			$("#lesson_data").html(html);
			$.hideLoading();
			$("#lesson_popup").popup();
		}else{
			$.alert('无班级信息','')
		}
	})
})

function get_lesson(title,id){
	$("#lesson").val(title);
	$("#lesson").attr("data-values",id);
	
	$("#xueqi").val('');
	$("#xueqi").attr("data-values",'0');
	$("#total").val('');
	
	$.closePopup();
	$("#xueqi").trigger('click');
}

$("#xueqi").click(function(){
	var lid = $("#lesson").attr("data-values");
	var title = $("#lesson").val();
	var tid = $(this).attr('data-values');
	if(!tid) tid=0;
	
	var studentstatus = $("input[name=studentstatus]").val();
	$.showLoading();
	$.get('/api/ygcl/getxueqi_new_for_midbm',{lid:lid,studentstatus:studentstatus},function(ret){
		if(ret.status){
			var data = {
				'tid':tid,
				'title':title,
				'list':ret.data.items
			}
			var html = template("xueqi_data_html", data);
			$("#xueqi_data").html(html);
			$.hideLoading();
			$("#xueqi_popup").popup();
		}else{
			$.alert('无学期信息','');
		}
	})
})

function get_xueqi(tid,title,value){
	var lid = $("#lesson").attr("data-values");//lessonid
	$.post('/api/ygcl/baomingcheck',{tid:tid,lid:lid},function(ret){
		if(ret.status){
			$("#xueqi").val(title);
			$("#xueqi").attr("data-values",tid);
			//$("#total").val(value);
			$.closePopup();
			$('.banjiDom').show();
		}else{
			$.alert("<span style='color:red'>"+ret.info+"</span>",'');
		}
	})
}

template.helper('decodehtmljson', function (str) {
	str = str.replace(new RegExp(/(\/\/&quot;)/g),'');
	str = str.replace(/&amp;/gi, '&');
	str = str.replace(/&nbsp;/gi, ' ');
	str = str.replace(/&quot;/gi, '"');
	str = str.replace(/&#39;/g, "'");
	str = str.replace(/&lt;/gi, '<');
	str = str.replace(/&gt;/gi, '>');
	//str = str.replace(/<br[^>]*>(?:(rn)|r|n)?/gi, '\n');
	return str;
});

$(".btncheckorder").click(function(){
	var thisBtn = $(this);
	if(thisBtn.attr('disabled') == 'disabled') {
        return;
	}
	var stunam=$("input[name=studentname]").val();
	if(stunam == ''){
		$.alert("姓名不能为空",'');
		return false;
	}
	var birthday=$.trim($("input[name=birthday]").val());
	if(birthday == ''){
		$.alert("请选择出生日期",'');
		return false;
	}
	var mobile=$("input[name=mobile]").val();
	if(mobile == ''){
		$.alert("手机号码不能为空",'');
		return false;
	}
	var jzxm=$("input[name=jzxm]").val();
	if(jzxm == ''){
		$.alert("家长姓名不能为空",'');
		return false;
	}
	var xueqi = $("#xueqi").val();
	var xiaoqu = $("#xiaoqu").val()
	if(xueqi == '' || xiaoqu == ''){
		$.alert("请先选择校区、班级、课程和学期",'');
		return false;
	}
	var total = $("#total").val();
	if(total == ''){
		$.alert("请输入金额",'');
		return false;
	}
	
	var data = {
		uid:$("input[name=uid]").val(),
		studentstatus:'midpay',
		stuname:stunam,
		birthday:birthday,
		tel:mobile,
		jzxm:jzxm,
		did:$("#xiaoqu").attr("data-values"),
		xiaoqu:$("#xiaoqu").val(),
		cid:$("#banji").attr("data-values"),
		banji:$("#banji").val(),
		lid:$("#lesson").attr("data-values"),
		lesson:$("#lesson").val(),
		tid:$("#xueqi").attr("data-values"),
		xueqi:$("#xueqi").val(),
		total:total,
		remark:$("#beizhu").val(),
		type:'midbm'
	};
	$.showLoading();
	thisBtn.attr('disabled', 'disabled');
	$.post('/api/ygcl/saveinfo',data,function(data){
		$.hideLoading();
		thisBtn.removeAttr('disabled');
		if(data.status){
			//console.log(data);
			location.href="/weixin/pay/index/id/"+data.data+".html";
		}else{
			$.alert("<span style='color:red'>"+data.info+"</span>",'');
		}
	});
})
</script>
</block>
